package _15_generics._15_8;

/**
 * 使用模板方法创建对象
 */
public class _04_CreatorGeneric {
    public static void main(String[] args) {
        Creator c = new Creator();
        c.f();
    }
}

abstract class GenericWithCreate<T> {
    T element;
    public GenericWithCreate(){
        this.element = create();
    }
    abstract T create();
}
class X {}

class Creator extends GenericWithCreate<X> {

    @Override
    X create() {
        return new X();
    }
    public void f(){
        System.out.println(element.getClass().getSimpleName());
    }
}